package com.hnevc.examliqiang;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import android.widget.ImageView;
import java.util.List;
import com.squareup.picasso.Picasso;

/**
 * Created by Administrator on 2017/12/12.
 */

public class MyBaseAdapter extends BaseAdapter {

    Context context; //指向Activity
    List<Food> foodList; //指向Activity中的食物列表

    public MyBaseAdapter(Context context, List<Food> foodList) {
        this.context = context;
        this.foodList = foodList;
    }

    @Override
    public int getCount() {
        return foodList.size();
    }

    @Override
    public Object getItem(int position) {
        return foodList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return foodList.get(position).getFoodId();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        View view = LayoutInflater.from(context).inflate(R.layout.list_item, null);

        TextView mTvFoodName = (TextView) view.findViewById(R.id.id_iv_foodName);
        mTvFoodName.setText(foodList.get(position).getFoodName());
        //TODO 功能实现2 显示食物的详细信息
        TextView mTvFoodDesc = (TextView) view.findViewById(R.id.id_iv_foodDesc);
        mTvFoodDesc.setText(foodList.get(position).getFoodDesc());
        Food food = foodList.get(position);

               ImageView mIvFoodPic = (ImageView) view.findViewById(R.id.id_iv_foodPic);

               String imageUrl="http://10.1.66.232:8080/RestaurantServer/uploadFoodImage/"+ food.getFoodPic();

                Picasso.with(context)
                        .load(imageUrl)
                        .into(mIvFoodPic);



        return view;
    }
}